package com.hht.study.javaBase.clone;

/**
 * @author hht
 * @date 2022/3/4
 */
public class CloneTest {

    public static void main(String[] args) {
        Person person1 = new Person();
        person1.setAddress(new Address());
        Person person2 = person1.clone();
        System.out.println(person1==person2);
        System.out.println(person1.getAddress()==person2.getAddress());
    }

    static class Person implements Cloneable{
        private Address address;

        @Override
        protected Person clone() {
            try {
                return (Person) super.clone();
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
                return null;
            }
        }

        public Address getAddress() {
            return address;
        }

        public void setAddress(Address address) {
            this.address = address;
        }
    }

    static class Address{

    }
}
